#include <iostream>
#include <unordered_set>
#include <string>
using namespace std;

unordered_set<char> hh {'2', '0', '1', '9'};

bool check(int i)
{
    string s = to_string(i);
    for(auto e: s)
        if(hh.count(e))
            return true;
    return false;
}

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; ++i)
        if(check(i))
            ans += i;
    cout << ans << endl;
    return 0;
}